#pragma once
#include <Rz/Object.h>
#include <Rz/Graphics/Math/Vector2.h>
#include <Rz/Graphics/Math/Vector3.h>
#include "IDeviceResource.h"
#include "IRenderDevice.h"
#include "Geometry.h"
#include "GeometryBuilder.h"
#include "VertexDescriptions/PositionTexture.h"

namespace Rz { namespace Graphics { namespace Render {

class FullScreenQuad :
	public Object,
	public IDeviceResource
{
	public:
		RZ_RTTI(Rz::Graphics::Render, FullScreenQuad);
		RZ_RTTI_IMPLEMENTS(Object, IDeviceResource);
		RZ_RTTI_END;

		FullScreenQuad(IRenderDevice* renderDevice)
		{
			this->SetRenderDevice(renderDevice);
			this->BuildQuad();
		}

		void Draw()
		{
			this->GetRenderDevice()->DrawIndexedPrimitives(PrimitiveType::TriangleList, _quadGeometry->GetVertexArray());
		}

	protected:
		void BuildQuad()
		{
			GeometryBuilder<VertexDescriptions::PositionTexture> builder(this->GetRenderDevice());

			VertexDescriptions::PositionTexture
				BL(Math::Vector3(-1.0f, -1.0f, 0.0f), Math::Vector2(0.0f, 0.0f)),
				BR(Math::Vector3( 1.0f, -1.0f, 0.0f), Math::Vector2(1.0f, 0.0f)),
				TL(Math::Vector3(-1.0f,  1.0f, 0.0f), Math::Vector2(0.0f, 1.0f)),
				TR(Math::Vector3( 1.0f,  1.0f, 0.0f), Math::Vector2(1.0f, 1.0f));

			builder.AddQuad(BR, TR, TL, BL);

			_quadGeometry = builder.ToGeometry();
		}

	private:
		Ptr<Geometry> _quadGeometry;
};

} } }
